package edu.sctu.zhu.dao;

import edu.sctu.zhu.bean.Addresses;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zhu on 2015/11/24.
 */
@Repository
@Transactional
public interface AddressesDao extends CrudRepository<Addresses,Long>{
    @Query(value = " select * from addresses where addresses.fans_id=? ",nativeQuery = true)
    public List<Addresses> findByFans(Long id);

    @Query(value = " select * from addresses where addresses.fans_id=? And addresses.flag=?",nativeQuery = true)
    public List<Addresses> findByFansAndflag(Long id,boolean flag);

    @Modifying(clearAutomatically = true)
    @Query(value = " update addresses SET flag=? WHERE id=? "  , nativeQuery = true)
    public void setStatus(boolean flag,Long id);
}
